local SarfFix2_cameraCVar = "cameraDistanceMaxFactor";
local SarfFix2_cameraMaxValue = 4;

function SarfFix2:SetCameraMaxValue(value)
	SarfFix2_cameraMaxValue = value;
	SarfFix2:UpdateCameraMaxValue();
end

function SarfFix2:UpdateCameraMaxValue()
	--ConsoleExec("CameraDistanceMaxFactor "..SarfFix2_cameraMaxValue);
	if ( type(UIOptionsFrameSliders) == "table" ) then
		for k, v in pairs(UIOptionsFrameSliders) do
			if ( v.cvar == SarfFix2_cameraCVar ) then
				v.maxValue = SarfFix2_cameraMaxValue;
				SetCVar(v.cvar, v.maxValue);
				return;
			end
		end
	end
	-- OK, failed to find the max distance in the options. Attempt to do it manually.
	SetCVar(SarfFix2_cameraCVar, SarfFix2_cameraMaxValue);
end

function SarfFix2:SetupCamera()
	SarfFix2:HookEvent("CVAR_UPDATE", function() SarfFix2:UpdateCameraMaxValue() end);
	
	SarfFix2:UpdateCameraMaxValue();
end


SarfFix2:SetupCamera();